﻿using System.Collections;

namespace _23_C_中Hashtable以及取值顺序问题
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#中Hashtable集合";

            ////键值对 字典一样

            //Hashtable hashtable = new Hashtable();
            //hashtable.Add("hash1", "王重阳");
            //hashtable.Add("hash2", "欧阳锋");
            //hashtable.Add("hash3", "黄药师");
            //hashtable.Add("hash4", "洪七公");
            //hashtable.Add("hash5", "一灯大师");

            ////hashtable.Remove("hash4");
            ////hashtable.Clear();

            //foreach (DictionaryEntry item in hashtable)
            //{
            //    Console.WriteLine($"Key:{item.Key}-value:{item.Value}");
            //}
            ////无规则
            ///

            MyHashtable hashtable = new MyHashtable();
            hashtable.Add("hash1", "王重阳");
            hashtable.Add("hash2", "欧阳锋");
            hashtable.Add("hash3", "黄药师");
            hashtable.Add("hash4", "洪七公");
            hashtable.Add("hash5", "一灯大师");

            //hashtable.Remove("hash4");
            //hashtable.Clear();

            foreach (string key in hashtable.Keys)
            {
                Console.WriteLine($"Key:{key} value:{hashtable[key]}");
            }
            //其实还是无序的 换了排序方式
            //foreach (DictionaryEntry item in hashtable)
            //{
            //    Console.WriteLine($"Key:{item.Key}-value:{item.Value}");
            //}

            Console.ReadKey();
        }
    }
}
